﻿// ***********************************************************************
// Project			: Micua
// Assembly         : Micua.Core
// Author           : iceStone
// Created          : 2013-11-23 22:40
//
// Last Modified By : iceStone
// Last Modified On : 2013-11-23 22:41
// ***********************************************************************
// <copyright file="FilterConfig.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary>缺少注释</summary>
// ***********************************************************************

using System.Web.Mvc;
using System.Web.Routing;
using Micua.Core.Routing.Filter;
using Micua.Core.Tracing.Filter;
using Micua.UI.Filter;

namespace Micua.UI.Config
{
    /// <summary>
    /// 过滤器配置
    /// </summary>
    /// <remarks>
    ///  2013-11-23 22:41 Created By iceStone
    /// </remarks>
    public class FilterConfig
    {
        /// <summary>
        /// 注册全局过滤器
        /// </summary>
        /// <remarks>
        ///  2013-11-23 22:41 Created By iceStone
        /// </remarks>
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            //注册去除重复URL筛选器。
            filters.Add(new RemoveDuplicateUrlFilter());
            //注册登录状态筛选器。
            filters.Add(new LoginStatusFilter());
            //注册异常跟踪筛选器。
            filters.Add(new ExceptionFilter());
            //GlobalFilters.Filters.Add(new HandleErrorAttribute());
        }
    }

    ///// <summary>
    ///// 重复URL过滤器.
    ///// </summary>
    ///// <remarks>
    /////  2013-12-07 21:27 Created By iceStone
    ///// </remarks>
    //public class RemoveDuplicateContentAttribute : ActionFilterAttribute
    //{
    //    /// <summary>
    //    /// 在执行操作方法之前由 ASP.NET MVC 框架调用。
    //    /// </summary>
    //    /// <remarks>
    //    ///  2013-12-07 21:27 Created By iceStone
    //    /// </remarks>
    //    /// <param name="filterContext">筛选器上下文。</param>
    //    public override void OnActionExecuting(ActionExecutingContext filterContext)
    //    {
    //        var routes = RouteTable.Routes;
    //        var requestContext = filterContext.RequestContext;
    //        var routeData = requestContext.RouteData;
    //        var dataTokens = routeData.DataTokens;
    //        if (dataTokens["area"] == null)
    //            dataTokens.Add("area", string.Empty);
    //        var vpd = routes.GetVirtualPathForArea(requestContext, routeData.Values);
    //        if (vpd != null)
    //        {
    //            var virtualPath = vpd.VirtualPath.ToLower();
    //            var request = requestContext.HttpContext.Request;
    //            if (!string.Equals(virtualPath, request.Path))
    //            {
    //                filterContext.Result = new RedirectResult(virtualPath + request.Url.Query, true);
    //            }
    //        }
    //        base.OnActionExecuting(filterContext);
    //    }
    //}
}